﻿using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Grid;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_User_List : BaseForm
    {
        ServiceBase service = new ServiceBase();
        public Base_User_List()
        {
            InitializeComponent();
            this.cmbUserType.Properties.NullText = "";
            this.cmbUserType.Properties.Columns.Add(new LookUpColumnInfo("Key", 30, "类型代码"));
            this.cmbUserType.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "类型名称"));
            this.cmbUserType.Properties.DataSource = ConstAppConfig.DicUserType.ToList();
            this.cmbUserType.Properties.DisplayMember = "Value";
            this.cmbUserType.Properties.ValueMember = "Key";
            BindData();
        }

        private void BindData()
        {
            string UserType = string.Empty;
            if (cmbUserType.Text == "" || cmbUserType.EditValue == null || cmbUserType.EditValue.ToSafeString().Length == 0)
            {
            }
            else
            {
                UserType = cmbUserType.EditValue.ToSafeString();
            }
            using (DataTable dt = service.GetUserTable(txtLoginName.Text.ToSafeString(), txtName.Text.ToSafeString(), UserType.ToSafeString()))
            {
                dgMac.DataSource = dt;
            }
        }

        private void benQuery_Click(object sender, EventArgs e)
        {
            BindData();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Base_User_Option option = new Base_User_Option(string.Empty);
            if (option.ShowDialog() == DialogResult.OK)
            {
                this.BindData();
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            GridView rows = sender as GridView;
            int[] inteurm = rows.GetSelectedRows();
            if (inteurm != null && inteurm.Length > 0)
            {
                string strUserID = rows.Rows[inteurm[0]].DataRow["UserID"].ToSafeString();
                Base_User_Option option = new Base_User_Option(strUserID);
                if (option.ShowDialog() == DialogResult.OK)
                {
                    this.BindData();
                }
            }
        }
    }
}
